define(function(require, exports, module) {
    'use strict';

    var $ = require('jquery');
    var validate = require('plugins/validate/validate.method');
    require('plugins/validate/validate');
    require('plugins/serializeJSON');
    var io = require('plugins/request');
    var box = require('plugins/box/box');

    $('#jForm').valid({
        when: 'submit',
        fields: {
            '#name':{
                required: true,
                message: '请填写您的姓名'
            },
            "#age":{
                required: true,
                message: '请填写您的年龄',
                test: validate.digits
            },
            "#phone":{
                required: true,
                message: '请填写您的手机号码',
                test: validate.mobile
            },
            "#qq":{
                required: true,
                message: '请填写您的QQ号码',
                test: validate.digits
            },
            "#wx":{
                required: true,
                message: '请填写您的微信号'
            }
        },
        submitButton: '.jSubmit',
        errorTemplate: function(error){
            return $('<span class="error-tips">'+error.message+'</span>');
        },
        happy: function(){
            var json = $('#jForm').serializeJSON();
            var $dom = $('#jSubmit');
            if($dom.hasClass('disabled')){
                return false;
            }
            $dom.addClass('disabled');
            io.post('', json, function(rst){
                box.tips(rst.data.msg);
                window.location.reload();
                $dom.removeClass('disabled');
            }, function(rst){
                box.error(rst.msg);
                $dom.removeClass('disabled');
            });
        }
    });

    $('#jForm').on('submit', function(){
        return false;
    });

});
